package com.example.programme.home;


import androidx.annotation.RequiresApi;
import androidx.fragment.app.Fragment;

import android.app.Activity;
import android.app.ActivityOptions;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.example.programme.LoginActivity;
import com.example.programme.R;

public class PersonCenterFragment extends Fragment {
  Button back;
  TextView textView;
    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        SharedPreferences sharedPreferences = getActivity().getSharedPreferences("User_Account",
                Activity.MODE_PRIVATE);
        String name=sharedPreferences.getString("name",null);
        String password=sharedPreferences.getString("password",null);
        textView=getActivity().findViewById(R.id.textView);
        textView.setText(name);

        /**
         *退出登录
         */
        back=getActivity().findViewById(R.id.backlogin);
        back.setOnClickListener(new View.OnClickListener() {
            //@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
            @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(getActivity(), LoginActivity.class);
                startActivity(intent,
                        ActivityOptions.makeSceneTransitionAnimation(getActivity()).toBundle());
                  //startActivity(intent);
                  getActivity().finish();

            }
        });

         Button accountsafty =getActivity().findViewById(R.id.accountsafty);
         accountsafty.setOnClickListener(new View.OnClickListener() {
           //  @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
             @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
             @Override
             public void onClick(View view) {
                 Intent intent = new Intent(getActivity(), SetAccountAcivity.class);
             // 开始下一个页面
                 startActivity(intent,
                         ActivityOptions.makeSceneTransitionAnimation(getActivity()).toBundle());
                   // startActivity(intent);
             }
         });


    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_personcenter, container, false);
    }
}